package com.wkk.nursinghome.service.impl;

import com.wkk.nursinghome.convert.Age;
import com.wkk.nursinghome.dao.IEmployeeDao;
import com.wkk.nursinghome.domain.Employee;
import com.wkk.nursinghome.service.IEmployeeService;
import org.springframework.stereotype.Service;
import org.apache.commons.lang3.StringUtils;
import javax.annotation.Resource;
import java.util.List;

@Service
public class EmployeeServiceImpl implements IEmployeeService {
    //注入对象
    @Resource
    private IEmployeeDao employeeDao;

    //实现方法，获取所有信息
    @Override
    public List<Employee> selectAll() {
        List<Employee> employees = employeeDao.selectAll();
        for (Employee employee : employees) {
            String age = employee.getAge();
             age = Age.getPersonAgeByBirthDate(age);
             employee.setAge(age);
        }
        //for (Employee employee : employees) {
        //    System.out.println(employee);
        //}
        return employees;
    }

    //增加信息
    @Override
    public void addEmployee(Employee employee) {
        employeeDao.insertEmployee(employee);
    }

    //修改信息
    @Override
    public boolean updateEmployee(Employee employee) {
        return employeeDao.updateEmployee(employee) > 0;
    }

    //根据编号查询信息
    @Override
    public Employee queryById(Integer id) {
        return employeeDao.selectEmployeeById(id);
    }

    //根据编号删除信息
    @Override
    public boolean deleteEmployeeById(Integer id) {
        //判断数据库中是否有数据受影响以返回操作是否成功
        return employeeDao.deleteEmployeeById(id) > 0;
    }

    //根据条件查询
    @Override
    public List<Employee> selectByCondition(Employee employee) {
        List<Employee> employees = employeeDao.getEmployeeByCondition(employee);
        for (Employee employee1 : employees) {
            String age = employee1.getAge();
            age = Age.getPersonAgeByBirthDate(age);
            employee1.setAge(age);
        }
        return employees;
    }

    @Override
    public boolean login(Integer id, String name) {
        int count=employeeDao.login(id,name);
        System.out.println(count);
        if(count>0) {
            return true;
        }
        return false;
    }
}
